// pages/jcbq/jcbq.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    template:{},
    img:'../../images/jichou.png',// https://jichou.shadiao.app/jichou.png
    text:'2022年2月8日,阴，群主拒绝了女装，这个仇，我先记下了'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  // 输入
  input(e){
    this.setData({
      text:e.detail.value
    })
  },

  // 开始绘图
  start_create(){
    this.setData({
      template:{
        background: '#ffffff',
        width: '300px',
        height: '320px',
        views:[
          {
            type: "image",
            url: this.data.img,
            css: {
              width: "252px",
              height: "197px",
              top: "20px",
              left:'24px'
            },
          },
          {
            type: "text",
            text: this.data.text,
            css: {
              width: "252px",
              right: "24px",
              top: "230px",
              fontSize: "16px",
              maxLines: 4,
              lineHeight:'25px'
            },
          }
        ]
      }
    })
  },

  // 上传图片
  uploade_img(){
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        var fsm = wx.getFileSystemManager()
        that.setData({
           img:'data:image/jpg;base64,'+fsm.readFileSync(tempFilePaths[0],'base64')
        })
      }
    })
  },

  onImgOK(e) {
    console.log('生成成功:'+e.detail.path)
    wx.showShareImageMenu({
      path:  e.detail.path,
      fail: err => {
        console.log(err)
      }
    })
  },

    // 领取红包
    nav_mini(e) {
      var type = e.currentTarget.dataset.type
      var path = ''
      var id = ''
      var that = this
      if (type == 1) {
        id = 'wxece3a9a4c82f58c9'
        path = "ele-recommend-price/pages/guest/index?chInfo=ch_wechat_chsub_Card&_ltracker_f=&inviterId=98e959f"
      } else if (type == 2) {
        id = 'wxece3a9a4c82f58c9'
        path = "taoke/pages/shopping-guide/index?scene=dBkV6ku"
      } else if (type == 3) {
        id = 'wx2c348cf579062e56'
        path = "outer_packages/r2xinvite/coupon/coupon?inviteCode=NnOIp-QOs8SiYF1dcSlL5r8phPrCf6qkH7evMyjIoup2NXxNCLYcBbd3bqpv2X2IkP84iu9RDt0ByI5WVKnmE_pc0u4Ds8Tr4YDQjQ9URZZ55n7T0Y6V3fj7hAGdMgef5g7Zq79Fa25_AdjNWgltSGGaXqRfd8wSe_kjDAU8Wjo"
      } else if (type == 4) {
        id = 'wxece3a9a4c82f58c9'
        path = "pages/sharePid/web/index?scene=s.click.ele.me%2FKyADSju"
      }
      wx.navigateToMiniProgram({
        appId: id,
        path: path,
        success: function () {},
      })
    },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '给你分享一个记仇表情包生成器吧',
      path: '/pages/jcbq/jcbq',
    };
  },

  onShareTimeline: function() {
    return {
      title: '给你分享一个记仇表情包生成器吧',
      path: '/pages/jcbq/jcbq',
    };
  }
})